package com.wing.warehouse.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.enums.MoveDownWarehouseStatusEnum;
import com.wing.warehouse.dao.MoveDownWarehouseItermDao;
import com.wing.warehouse.model.entity.MoveDownWarehouseIterm;
import com.wing.warehouse.model.request.MoveDownWarehouseItermForm;
import com.wing.warehouse.model.response.MoveDownWarehouseItermVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 移库下货详情表-ServiceImpl
 *
 * @author
 */
@Service
@Slf4j
public class MoveDownWarehouseItermServiceImpl extends ServiceImpl<MoveDownWarehouseItermDao, MoveDownWarehouseIterm> implements MoveDownWarehouseItermService {

    @Override
    public int add(MoveDownWarehouseItermForm moveDownWarehouseItermForm) {

        //校验

        MoveDownWarehouseIterm moveDownWarehouseIterm =new MoveDownWarehouseIterm();
        CopyOptions copyOptions = CopyOptions.create()
        .setEditable(MoveDownWarehouseIterm.class)
        .setIgnoreError(true)
        .setIgnoreNullValue(true);
        BeanUtil.copyProperties(moveDownWarehouseItermForm, moveDownWarehouseIterm, copyOptions);

        return baseMapper.insert(moveDownWarehouseIterm);
    }

    @Override
    public List<MoveDownWarehouseItermVO> list4app(Map<String, Object> params) {
        return baseMapper.list4app(params);
    }

    @Override
    public Page<MoveDownWarehouseItermVO> pageList4app(Page page, Map<String, Object> params) {
        List<MoveDownWarehouseItermVO> list = baseMapper.list4app(page, params);
        if (CollectionUtil.isNotEmpty(list)) {
            list.stream().forEach(o-> {
                o.setStatusName(MoveDownWarehouseStatusEnum.getDescByCode(o.getStatus()));
            });
        }
        page.setRecords(list);
        return page;
    }

    @Override
    public MoveDownWarehouseItermVO get4appById(Long id) {
        return baseMapper.get4appById(id);
    }

}
